package cc.rengu.igas.bomp.core.service.trans;

import cc.rengu.igas.bomp.common.constant.BompAppParamConstant;
import cc.rengu.igas.bomp.common.dao.*;
import cc.rengu.igas.bomp.common.dao.impl.*;
import cc.rengu.igas.bomp.common.entity.*;
import cc.rengu.igas.bomp.common.enums.FundTypeEnum;
import cc.rengu.igas.bomp.common.enums.MchntTypeEnum;
import cc.rengu.igas.bomp.common.enums.RespCodeEnum;
import cc.rengu.igas.bomp.core.service.base.ManageService;
import cc.rengu.igas.bomp.facade.bean.MchntInfoBean;
import cc.rengu.igas.bomp.facade.request.MchntInfoListQueryRequest;
import cc.rengu.igas.bomp.facade.response.MchntInfoListQueryResponse;
import cc.rengu.igas.share.common.enums.RoleTypeEnum;
import cc.rengu.igas.share.common.util.SensitiveDataUtil;
import cc.rengu.igas.share.core.model.MchntBindInfo;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.bean.PageInfo;
import cc.rengu.oltp.utility.bean.PageResult;
import cc.rengu.oltp.utility.util.BeanUtil;
import cc.rengu.oltp.utility.util.ConvertUtil;
import cc.rengu.oltp.utility.util.StringUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import org.springframework.util.CollectionUtils;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 商户信息列表查询服务
 * Created by 王成 on 2020/3/9
 */
public class MchntInfoListQueryService extends ManageService {
    @Override
    protected Object bizBeforeCust() throws Exception {
        MchntInfoListQueryRequest mchntInfoListQueryRequest = new MchntInfoListQueryRequest();
        ConvertUtil.convertOutput(mchntInfoListQueryRequest);
        /* 必填请求参数合法性检查 */
        if (null == mchntInfoListQueryRequest.getUserId() || mchntInfoListQueryRequest.getUserId().isEmpty()) {
            rglog.error("用户编号<{}>为空!", mchntInfoListQueryRequest.getUserId());
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
        return mchntInfoListQueryRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        MchntInfoListQueryRequest mchntInfoListQueryRequest = (MchntInfoListQueryRequest) request;
        MchntInfoListQueryResponse mchntInfoListQueryResponse = new MchntInfoListQueryResponse();
        BeanUtil.beanCopy(mchntInfoListQueryRequest, mchntInfoListQueryResponse);
        BizResponse bizResponse = new BizResponse();
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        MchntBaseInfoMapper mchntBaseInfoMapper = new MchntBaseInfoMapperImpl();

        String instId = mchntInfoListQueryRequest.getHeader().getInstId();
        String userId = mchntInfoListQueryRequest.getUserId();

        /*根据不同的渠道查询*/
        String chanlId = mchntInfoListQueryRequest.getHeader().getChanlId();
        int pageIndex = mchntInfoListQueryRequest.getPageIndex();
        int pageSize = mchntInfoListQueryRequest.getPageSize();
        if (StringUtil.isEmptyOrNull(chanlId) || StringUtil.isEmptyOrNull(instId) || StringUtil.isEmptyOrNull(String.valueOf(pageIndex)) || StringUtil.isEmptyOrNull(String.valueOf(pageSize))) {
            rglog.error("必填性校验失败!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPageIndex(pageIndex);
        pageInfo.setPageSize(pageSize);

        String userRole = xmlTreeUtil.getXmlTreeStringValue("userRole");
        String managerId = "";
        String signInstId = "";
        if (!BompAppParamConstant.MCMP_CHANNEL.equals(chanlId)) {
            if (RoleTypeEnum.MANAGER.getRoleType().equals(userRole) || RoleTypeEnum.MANAGER_AUDIT.getRoleType().equals(userRole)) {
                /*根据openId查询拓展经理*/
                ManagerInfo managerInfo = null;
                ManagerInfoMapper managerInfoMapper = new ManagerInfoMapperImpl();
                if ("APP".equals(chanlId)){
                    managerInfo = managerInfoMapper.selectManagerInfoById(instId,userId);
                }else {
                    managerInfo = managerInfoMapper.selectManagerInfoByOpenId(instId, userId);
                }
                if (managerInfo == null) {
                    rglog.error("未查询到用户");
                    throw new BizException(RespCodeEnum.QUERY_AUTH_USER_IS_NULL.getRespCode(), RespCodeEnum.QUERY_AUTH_USER_IS_NULL.getRespDesc());
                }
                /*根据拓展经理工号查询相关的商户*/
                managerId = managerInfo.getManagerId();
                signInstId = managerInfo.getSignInstId();
            }

            if (RoleTypeEnum.MCHNT.getRoleType().equals(userRole)) {
                List<MchntBindInfo> mchntBindInfoList = xmlTreeUtil.getXmlTreeListObjectValue("mchntBindInfo", MchntBindInfo.class);
                MchntBindInfo mchntBindInfo = mchntBindInfoList.stream().filter(item -> item.getBindUserRole().equals(userRole)).collect(Collectors.toList()).get(0);
                if (MchntTypeEnum.CHAIN_MCHNT.getMchntType().equals(mchntBindInfo.getMchntType())
                        && (StringUtil.isEmptyOrNull(mchntInfoListQueryRequest.getChainMchntNo())) || !mchntBindInfo.getMchntNo().equals(mchntInfoListQueryRequest.getChainMchntNo())) {
                    rglog.error("连锁商户法人查询商户列表信息时，连锁商户号必填！chainMchntNo:{}, bindMchntNo:{}", mchntInfoListQueryRequest.getChainMchntNo(), mchntBindInfo.getMchntNo());
                    throw new BizException(RespCodeEnum.ILLEGAL_OPERATION.getRespCode(), RespCodeEnum.ILLEGAL_OPERATION.getRespDesc());
                }

                if (!MchntTypeEnum.CHAIN_MCHNT.getMchntType().equals(mchntBindInfo.getMchntType())) {
                    if (StringUtil.isEmptyOrNull(mchntInfoListQueryRequest.getMchntNo()) || !mchntBindInfo.getMchntNo().equals(mchntInfoListQueryRequest.getMchntNo())) {
                        rglog.error("普通商户查询，商户号必填！chainMchntNo:{}, bindMchntNo:{}", mchntInfoListQueryRequest.getChainMchntNo(), mchntBindInfo.getMchntNo());
                        throw new BizException(RespCodeEnum.ILLEGAL_OPERATION.getRespCode(), RespCodeEnum.ILLEGAL_OPERATION.getRespDesc());
                    }
                }


            } else if (RoleTypeEnum.GROUP_MCHNT.getRoleType().equals(userRole)) {
                List<MchntBindInfo> mchntBindInfoList = xmlTreeUtil.getXmlTreeListObjectValue("mchntBindInfo", MchntBindInfo.class);
                MchntBindInfo mchntBindInfo = mchntBindInfoList.stream().filter(item -> item.getBindUserRole().equals(userRole)).collect(Collectors.toList()).get(0);
                if (StringUtil.isEmptyOrNull(mchntInfoListQueryRequest.getGroupMchntNo()) || !mchntBindInfo.getMchntNo().equals(mchntInfoListQueryRequest.getGroupMchntNo())) {
                    rglog.error("集团商户管理员查询商户列表信息时，集团商户号必填！groupMchntNo:{}, bindMchntNo:{}", mchntInfoListQueryRequest.getGroupMchntNo(), mchntBindInfo.getMchntNo());
                    throw new BizException(RespCodeEnum.ILLEGAL_OPERATION.getRespCode(), RespCodeEnum.ILLEGAL_OPERATION.getRespDesc());
                }
            } else if (RoleTypeEnum.PLAT_MCHNT.getRoleType().equals(userRole)) {
                List<MchntBindInfo> mchntBindInfoList = xmlTreeUtil.getXmlTreeListObjectValue("mchntBindInfo", MchntBindInfo.class);
                MchntBindInfo mchntBindInfo = mchntBindInfoList.stream().filter(item -> item.getBindUserRole().equals(userRole)).collect(Collectors.toList()).get(0);
                if (StringUtil.isEmptyOrNull(mchntInfoListQueryRequest.getPlatMchntNo()) || !mchntBindInfo.getMchntNo().equals(mchntInfoListQueryRequest.getPlatMchntNo())) {
                    rglog.error("平台商户管理员查询商户列表信息时，平台商户号必填！PlatMchntNo:{}, bindMchntNo:{}", mchntInfoListQueryRequest.getPlatMchntNo(), mchntBindInfo.getMchntNo());
                    throw new BizException(RespCodeEnum.ILLEGAL_OPERATION.getRespCode(), RespCodeEnum.ILLEGAL_OPERATION.getRespDesc());
                }
            } else if (RoleTypeEnum.AGENT_MCHNT.getRoleType().equals(userRole)) {
                List<MchntBindInfo> mchntBindInfoList = xmlTreeUtil.getXmlTreeListObjectValue("mchntBindInfo", MchntBindInfo.class);
                MchntBindInfo mchntBindInfo = mchntBindInfoList.stream().filter(item -> item.getBindUserRole().equals(userRole)).collect(Collectors.toList()).get(0);
                if (StringUtil.isEmptyOrNull(mchntInfoListQueryRequest.getAgentMchntNo()) || !mchntBindInfo.getMchntNo().equals(mchntInfoListQueryRequest.getAgentMchntNo())) {
                    rglog.error("代理商户管理员查询商户列表信息时，代理商户号必填！agentMchntNo:{}, bindMchntNo:{}", mchntInfoListQueryRequest.getAgentMchntNo(), mchntBindInfo.getMchntNo());
                    throw new BizException(RespCodeEnum.ILLEGAL_OPERATION.getRespCode(), RespCodeEnum.ILLEGAL_OPERATION.getRespDesc());
                }
            }

        } else {
            /*渠道为mcmp时处理*/
            AuthUserMapper authUserMapper = new AuthUserMapperImpl();
            AuthUser authUser = authUserMapper.selectAuthUserById(userId);
            if (authUser == null) {
                rglog.error("未查询到用户");
                throw new BizException(RespCodeEnum.QUERY_AUTH_USER_IS_NULL.getRespCode(), RespCodeEnum.QUERY_AUTH_USER_IS_NULL.getRespDesc());
            }
            managerId = authUser.getEmpNo();
            if (StringUtil.isEmptyOrNull(managerId)) {
                rglog.error("无empNo");
                throw new BizException(RespCodeEnum.QUERY_AUTH_USER_IS_NULL.getRespCode(), RespCodeEnum.QUERY_AUTH_USER_IS_NULL.getRespDesc());
            }
        }

        MchntBaseInfo mchntBaseInfo = new MchntBaseInfo();
        if (!BompAppParamConstant.MCMP_CHANNEL.equals(chanlId) && RoleTypeEnum.MANAGER.getRoleType().equals(userRole)) {
            mchntBaseInfo.setManagerId(managerId);
        }
        if (null != mchntInfoListQueryRequest.getMchntName() && !mchntInfoListQueryRequest.getMchntName().isEmpty()) {
            mchntBaseInfo.setMchntName("%" + mchntInfoListQueryRequest.getMchntName() + "%");
        }
        mchntBaseInfo.setInstId(instId);

        mchntBaseInfo.setMchntNo(mchntInfoListQueryRequest.getMchntNo());
        mchntBaseInfo.setChainMchntNo(mchntInfoListQueryRequest.getChainMchntNo());
        mchntBaseInfo.setSignInstId(mchntInfoListQueryRequest.getSignInstId());
        if (!BompAppParamConstant.MCMP_CHANNEL.equals(chanlId) && RoleTypeEnum.MANAGER_AUDIT.getRoleType().equals(userRole)) {
            mchntBaseInfo.setSignInstId(signInstId);
        }
        mchntBaseInfo.setPlatMchntNo(mchntInfoListQueryRequest.getPlatMchntNo());
        mchntBaseInfo.setGroupMchntNo(mchntInfoListQueryRequest.getGroupMchntNo());
        mchntBaseInfo.setAgentMchntNo(mchntInfoListQueryRequest.getAgentMchntNo());
        mchntBaseInfo.setMchntLevel(mchntInfoListQueryRequest.getMchntLevel());
        mchntBaseInfo.setIndustryType(mchntInfoListQueryRequest.getIndustryType());
        mchntBaseInfo.setMchntAttr(mchntInfoListQueryRequest.getMchntAttr());
        mchntBaseInfo.setMchntExpandTime(mchntInfoListQueryRequest.getExpandBeginTime());
        mchntBaseInfo.setRemark5(mchntInfoListQueryRequest.getExpandEndTime());
        mchntBaseInfo.setMchntStatus(mchntInfoListQueryRequest.getMchntStatus());
        mchntBaseInfo.setAuditStatus(mchntInfoListQueryRequest.getAuditStatus());
        mchntBaseInfo.setMchntArea(mchntInfoListQueryRequest.getMchntArea());
        String auditStatus = mchntInfoListQueryRequest.getAuditStatus();
        PageResult pageResult;
        if (!StringUtil.isEmptyOrNull(auditStatus) && auditStatus.length() == 1) {
            //1-审核员查询所有待审核
            //2-审核员查询自己审核通过
            //3-审核员/复核员查询自己审核拒绝
            //4-复核员查询所有待复核
            //5-审核员查自己审核通过/拒绝
            //6-复核员查自己审核通过/拒绝
            //7-复核员查自己审核通过
            if (!BompAppParamConstant.MCMP_CHANNEL.equals(mchntInfoListQueryRequest.getHeader().getChanlId())
                    && !"1".equals(auditStatus) && !"4".equals(auditStatus)
                    && (RoleTypeEnum.MANAGER_AUDIT.getRoleType().equals(userRole)
                    || RoleTypeEnum.MANAGER_RE_AUDIT.getRoleType().equals(userRole))) {
                //拓展经理审核员，查询 2-审核通过，3-审核拒绝，5-全部已审核 只查当前审核员的数据
                mchntBaseInfo.setLastAuditId(mchntInfoListQueryRequest.getUserId());
            }
            pageResult = mchntBaseInfoMapper.selectBompMchntBaseInfoByAuditStatus(mchntBaseInfo, pageInfo);
        } else if (!StringUtil.isEmptyOrNull(mchntBaseInfo.getSignInstId())) {
            pageResult = mchntBaseInfoMapper.selectBompMchntBaseInfoBySignInstId(mchntBaseInfo, pageInfo);
        } else {
            pageResult = mchntBaseInfoMapper.selectBompMchntBaseInfo(mchntBaseInfo, pageInfo);
        }

        if (null == pageResult || null == pageResult.getPageInfo() || null == pageResult.getResult()) {
            rglog.info("根据查询条件查询到0条信息!");
            bizResponse.setRespCode(RespCodeEnum.QUERY_DATA_IS_NULL.getRespCode());
            bizResponse.setRespDesc(RespCodeEnum.QUERY_DATA_IS_NULL.getRespDesc());
            mchntInfoListQueryResponse.setTotalPage(BompAppParamConstant.INT_ZERO);
            mchntInfoListQueryResponse.setTotalRows(BompAppParamConstant.INT_ZERO);
            bizResponse.setResult(mchntInfoListQueryResponse);
            return bizResponse;
        }

        List<MchntInfoBean> mchntInfoBeanList = new ArrayList<>();
        /* 根据取出记录条数做对应处理 */
        if (pageResult.getResult().isEmpty()) {
            rglog.info("根据查询条件查询到0条信息!");
            /* 按照接口转换基础产品信息并响应给请求方 */
            bizResponse.setRespCode(RespCodeEnum.QUERY_DATA_IS_NULL.getRespCode());
            bizResponse.setRespDesc(RespCodeEnum.QUERY_DATA_IS_NULL.getRespDesc());
            mchntInfoListQueryResponse.setTotalPage(BompAppParamConstant.INT_ZERO);
            mchntInfoListQueryResponse.setTotalRows(BompAppParamConstant.INT_ZERO);
            mchntInfoListQueryResponse.setRespCode(RespCodeEnum.QUERY_DATA_IS_NULL.getRespCode());
            mchntInfoListQueryResponse.setRespDesc(RespCodeEnum.QUERY_DATA_IS_NULL.getRespDesc());
            bizResponse.setResult(mchntInfoListQueryResponse);
            return bizResponse;
        } else {
            List<Object> detailList = pageResult.getResult();
            for (Object objTemp : detailList) {
                MchntBaseInfo item = (MchntBaseInfo) objTemp;
                MchntInfoBean mchntInfoBean = convMchntInfo(item, userRole);
                mchntInfoBeanList.add(mchntInfoBean);
            }
        }

        mchntInfoListQueryResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        mchntInfoListQueryResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        mchntInfoListQueryResponse.setPageSize(pageResult.getPageInfo().getPageSize());
        mchntInfoListQueryResponse.setPageIndex(pageResult.getPageInfo().getPageIndex());
        mchntInfoListQueryResponse.setTotalPage(pageResult.getPageInfo().getTotalPage());
        mchntInfoListQueryResponse.setTotalRows(pageResult.getPageInfo().getTotalRows());
        mchntInfoListQueryResponse.setMchntInfoList(mchntInfoBeanList);

        /* 按照接口转换基础产品信息并响应给请求方 */
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        bizResponse.setResult(mchntInfoListQueryResponse);
        return bizResponse;
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        MchntInfoListQueryResponse mchntInfoListQueryResponse = (MchntInfoListQueryResponse) bizResponse.getResult();
        ConvertUtil.convertInput(mchntInfoListQueryResponse);
    }

    /**
     * 查询结果转换
     *
     * @param mchntBaseInfo 商户基本信息
     */
    private MchntInfoBean convMchntInfo(MchntBaseInfo mchntBaseInfo, String userRole) {
        MchntInfoBean mchntInfoBean = new MchntInfoBean();
        try {
            BeanUtil.beanCopy(mchntBaseInfo, mchntInfoBean);
            /* 获取行业类别名称 */
            IndustryInfoMapper industryInfoMapper = new IndustryInfoMapperImpl();
            IndustryInfo industryInfo = industryInfoMapper.selectIndustryInfoByIndustryType(mchntBaseInfo.getIndustryType());
            if (null != industryInfo) {
                mchntInfoBean.setIndustryName(industryInfo.getIndustryName());
            }
            /* 获取微信商户信息 */
            WechatMchntInfoMapper wechatMchntInfoMapper = new WechatMchntInfoMapperImpl();
            WechatMchntInfo wechatMchntInfo = wechatMchntInfoMapper.selectWechatMchntInfoByPrimaryKey(mchntBaseInfo.getInstId(), mchntBaseInfo.getMchntNo());
            if (null != wechatMchntInfo) {
                mchntInfoBean.setWechatExpandStatus(wechatMchntInfo.getWechatEntryFlag());
                mchntInfoBean.setRealNameFlag(wechatMchntInfo.getRealNameFlag());
                mchntInfoBean.setRealNameApplyNo(wechatMchntInfo.getRealNameApplyNo());
                mchntInfoBean.setWechatMchntNo(wechatMchntInfo.getWechatMchntNo());
            }
            /* 获取支付宝商户信息 */
            AlipayMchntInfoMapper alipayMchntInfoMapper = new AlipayMchntInfoMapperImpl();
            AlipayMchntInfo alipayMchntInfo = alipayMchntInfoMapper.selectAlipayMchntInfoByPrimaryKey(mchntBaseInfo.getInstId(), mchntBaseInfo.getMchntNo());
            if (null != alipayMchntInfo) {
                mchntInfoBean.setAlipayExpandStatus(alipayMchntInfo.getAlipayEntryFlag());
                mchntInfoBean.setAlipayMchntNo(alipayMchntInfo.getAlipayMchntNo());
            }
            /* 获取银联商户信息 */
            CupsMchntInfoMapper cupsMchntInfoMapper = new CupsMchntInfoMapperImpl();
            CupsMchntInfo cupsMchntInfo = cupsMchntInfoMapper.selectCupsMchntInfoByPrimaryKey(mchntBaseInfo.getInstId(), mchntBaseInfo.getMchntNo());
            if (null != cupsMchntInfo) {
                mchntInfoBean.setCupsReportStatus(cupsMchntInfo.getCupsReportStatus());
            }
            /* 获取代理机构名称 */
            if (null != mchntBaseInfo.getAgentMchntNo() && !mchntBaseInfo.getAgentMchntNo().isEmpty()) {
                AgentInfoMapper agentInfoMapper = new AgentInfoMapperImpl();
                AgentInfo agentInfo = agentInfoMapper.selectAgentInfoByPrimaryKey(mchntBaseInfo.getInstId(), mchntBaseInfo.getAgentMchntNo());
                if (null != agentInfo) {
                    mchntInfoBean.setAgentMchntName(agentInfo.getAgentName());
                }
            }
            /* 获取签约机构名称 */
            OrganizationMapper organizationMapper = new OrganizationMapperImpl();
            Organization organization = organizationMapper.selectOrganizationByPrimaryKey(mchntBaseInfo.getInstId(), mchntBaseInfo.getSignInstId());
            if (null != organization) {
                mchntInfoBean.setSignInstName(organization.getOrgName());
            }

            MchntAcctInfoMapper mchntAcctInfoMapper = new MchntAcctInfoMapperImpl();
            MchntAcctInfo mchntAcctInfo = mchntAcctInfoMapper.selectMchntAcctInfoByPrimaryKey(mchntBaseInfo.getInstId(), mchntBaseInfo.getMchntNo(), "*", FundTypeEnum.SETTLE_TYPE.getFundCode());
            if (null != mchntAcctInfo) {
                if (BompAppParamConstant.MCHNT_ROLES.contains(userRole) && !StringUtil.isEmptyOrNull(mchntAcctInfo.getSettleAcctNo())) {
                    String acctNo = SensitiveDataUtil.desensitization("2", mchntAcctInfo.getSettleAcctNo()).split("\\|")[0];
                    mchntInfoBean.setSettleAcctNo(acctNo);
                } else {
                    mchntInfoBean.setSettleAcctNo(mchntAcctInfo.getSettleAcctNo());
                }
                mchntInfoBean.setAcctSignFlag(mchntAcctInfo.getAcctSignFlag());
            }

            if (BompAppParamConstant.MCHNT_ROLES.contains(userRole)) {
                if (!StringUtil.isEmptyOrNull(mchntBaseInfo.getMchntContactMobile())) {
                    String mobile = SensitiveDataUtil.desensitization("1", mchntBaseInfo.getMchntContactMobile()).split("\\|")[0];
                    mchntInfoBean.setContactMobile(mobile);
                }
                if (!StringUtil.isEmptyOrNull(mchntBaseInfo.getMchntContactPhone())) {
                    String phone = SensitiveDataUtil.desensitization("1", mchntBaseInfo.getMchntContactPhone()).split("\\|")[0];
                    mchntInfoBean.setContactMobilePhone(phone);
                }
            } else {
                mchntInfoBean.setContactMobile(mchntBaseInfo.getMchntContactMobile());
                mchntInfoBean.setContactMobilePhone(mchntBaseInfo.getMchntContactPhone());
            }

            ManagerInfoMapper managerInfoMapper = new ManagerInfoMapperImpl();
            List<ManagerInfo> managerInfoList = managerInfoMapper.selectBompManagerInfoByManagerId(mchntBaseInfo.getInstId(), mchntBaseInfo.getManagerId());
            if (!CollectionUtils.isEmpty(managerInfoList)) {
                ManagerInfo managerInfo = managerInfoList.get(0);
                if (BompAppParamConstant.MCHNT_ROLES.contains(userRole) && !StringUtil.isEmptyOrNull(managerInfo.getManagerPhone())) {
                    String mobile = SensitiveDataUtil.desensitization("1", managerInfo.getManagerPhone()).split("\\|")[0];
                    mchntInfoBean.setManagerPhone(mobile);
                } else {
                    mchntInfoBean.setManagerPhone(managerInfo.getManagerPhone());
                }
            }

            mchntInfoBean.setCompanyNature(mchntBaseInfo.getMchntNature());
            mchntInfoBean.setContactName(mchntBaseInfo.getMchntContactName());
            mchntInfoBean.setManagerName(mchntBaseInfo.getManagerName());

            /* 新加 创建时间、最后审核时间 */
            mchntInfoBean.setCreateTime(mchntBaseInfo.getCreateTime());
            mchntInfoBean.setLastAuditTime(mchntBaseInfo.getLastAuditTime());
        } catch (Exception e) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
            rglog.error("商户列表查询详细信息转换失败:{}", byteArrayOutputStream.toString());
        }

        return mchntInfoBean;
    }
}
